<?php

class AuthController extends BaseController {
    public function showLoginForm()
	{
		return View::make('login');
	}

    public function getPutsession()
    {
        $returnData       = array();
        $response         = "OK";
        $statusCode       = 200;
        $result           = null;
        $message          = "Adding username and role to sessions success.";
        $isError          = FALSE;
        $missingParams    = null;
		
        $input            = Input::all();
        $username         = (isset($input['username'])) ? $input['username']:null;
        $role             = (isset($input['role'])) ? $input['role']:null;
		
        if(!isset($username)){
            $missingParams[] = "username";
        }
        
        if(!isset($role)){
            $missingParams[] = "role";
        }
        
		if(isset($missingParams)){
            $isError = TRUE;
            $response = "FAILED";
            $statusCode = 400;
            $message = "Missing parameters : {".implode(', ', $missingParams)."}";
        }
		
        if(!$isError){ 
            try {
                Session::put('PLNRBBDist3_user', $username);
                Session::put('PLNRBBDist3_role', $role);
                
            } catch (Exception $e) {
                $response = "FAILED";
                $statusCode = 400;
                $message = $e->getMessage();
            } // */
        }

        $returnData = array(
            'response' => $response,
            'status_code' => $statusCode,
            'message' => $message,
            'result' => $result
            );

        return Response::json($returnData, $statusCode)->header('access-control-allow-origin', '*');
    }
    
	public function doLogout()
	{
        Session::flush();
        return Redirect::to('/');
	}
}

?>